package freejim.icu.highschoolhealthstatuspost.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
@Transactional
public interface UserRepository extends JpaRepository<User,Long> {
    User findByName(String name);

    @Query(value = "select id from tb_user where role = 'USER'",nativeQuery = true)
    List<Integer> getAllUserId();

    @Query(value = "select * from tb_user where role = 'USER' or role = 'LOCK'",nativeQuery = true)
    List<User> getAllUser();

    @Query(value = "select COUNT(*) from tb_user where role = 'USER'",nativeQuery = true)
    long getUserNum();

    @Query(value = "select id from tb_user where userid = ?1",nativeQuery = true)
    long getIdWithUserId(String userid);

    @Modifying
    @Query(value = "update tb_user set role = 'LOCK' where name = ?1")
    int lockUser(String username);

    @Modifying
    @Query(value = "update tb_user set role = 'USER' where name = ?1")
    int unLockUser(String username);


}
